package com.techfort.testguice;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.techfort.testguice.pojo.ListItem;

public class ManageItemsAdapter<T extends ListItem> extends ArrayAdapter<T> {

	
	List<T> items;
	private Context context;
	private int resource;
	
	public ManageItemsAdapter(Context context, int resource,
			int textViewResourceId, List<T> objects) {
		super(context, resource, textViewResourceId, objects);
		
		items = objects;
		this.context = context;
		this.resource = resource;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v==null){
			LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = li.inflate(resource, null);
		}
		
		final CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox);
		final TextView tv = (TextView) v.findViewById(R.id.title);
		tv.setText(items.get(position).getTitle());
		
		return v;
	}

}
